home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INSTALL / program files / Borland / Delphi6 / Demos / ActiveX / ShellExt / CopyHk.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-22  |  2KB  |  85 lines

  1. unit CopyHk;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, ComObj, ShlObj;
  7.  
  8. type
  9.   TCopyHook = class(TComObject, ICopyHook)
  10.   public
  11.     function CopyCallback(Wnd: HWND; wFunc, wFlags: UINT; pszSrcFile: PAnsiChar;
  12.       dwSrcAttribs: DWORD; pszDestFile: PAnsiChar; dwDestAttribs: DWORD): UINT; stdcall;
  13.   end;
  14.  
  15. const
  16.   Class_CopyHook: TGUID = '{29F97553-FBD6-11D1-AFC1-00A024D1875C}';
  17.  
  18. implementation
  19.  
  20. uses ComServ, ShellAPI, SysUtils, Registry;
  21.  
  22. function TCopyHook.CopyCallBack(Wnd: HWND; wFunc, wFlags: UINT; pszSrcFile: PAnsiChar;
  23.   dwSrcAttribs: DWORD; pszDestFile: PAnsiChar; dwDestAttribs: DWORD): UINT;
  24. // This is the method which is called by the shell for folder operations
  25. const
  26.   ConfirmMessage = 'Are you sure you want to %s ''%s''?';
  27. var
  28.   Operation: string;
  29. begin
  30.   case wFunc of
  31.     FO_COPY:
  32.       Operation := 'copy';
  33.     FO_DELETE:
  34.       Operation := 'delete';
  35.     FO_MOVE:
  36.       Operation := 'move';
  37.     FO_RENAME:
  38.       Operation := 'rename';
  39.     else
  40.       Operation := 'continue this operation on'
  41.   end;
  42.  
  43.   // confirm operation
  44.   Result := MessageBox(Wnd, PChar(Format(ConfirmMessage, [Operation, pszSrcFile])),
  45.     'Delphi CopyHook Shell Extension...' , MB_YESNOCANCEL);
  46. end;
  47.  
  48. type
  49.   TCopyHookFactory = class(TComObjectFactory)
  50.   public
  51.     procedure UpdateRegistry(Register: Boolean); override;
  52.   end;
  53.  
  54. procedure TCopyHookFactory.UpdateRegistry(Register: Boolean);
  55. var
  56.   ClassID: string;
  57. begin
  58.   if Register then begin
  59.     inherited UpdateRegistry(Register);
  60.  
  61.     ClassID := GUIDToString(Class_CopyHook);
  62.     CreateRegKey('Directory\shellex\CopyHookHandlers\DelphiCopyHook', '', ClassID);
  63.     if (Win32Platform = VER_PLATFORM_WIN32_NT) then
  64.       with TRegistry.Create do
  65.         try
  66.           RootKey := HKEY_LOCAL_MACHINE;
  67.           OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions', True);
  68.           OpenKey('Approved', True);
  69.           WriteString(ClassID, 'Delphi CopyHook Shell Extension Example');
  70.         finally
  71.           Free;
  72.         end;
  73.   end
  74.   else begin
  75.     DeleteRegKey('Directory\shellex\CopyHookHandlers\DelphiCopyHook');
  76.  
  77.     inherited UpdateRegistry(Register);
  78.   end;
  79. end;
  80.  
  81. initialization
  82.   TCopyHookFactory.Create(ComServer, TCopyHook, Class_CopyHook, '',
  83.     'Delphi CopyHook Shell Extension Example', ciMultiInstance, tmApartment);
  84. end.
  85.